document:Inefficient methods of use var total=db.foo.count ()var random = Math.floor (Math.random () *total)Db.foo.find (). Skip (Random). Limit (1) You can add an extra random key when inserting data:Db.people.insert ({"Name": "Joe", "Random": Math.random ()}) var random =math.random ()result= Db.people.findOne ({"random": {"$GT": Random}}) Advanced query Options:$maxscan: Specifies the maximum number of scanned documents in a queryDb.foo.find (crit
. Performance problems may occur when the skip is skipped too many documents. We recommend that you avoid this problem as much as possible.Sort: sort documents by specified keys. 1 is in ascending order and-1 is in descending order.
2. Advanced query options
Packaging query: Use sort, limit, or skip to further control the final result.
Useful configuration options:
$ Maxscan: integer indicates the maximum number of scanned documents to be queried.$ M
advance when they are sent to the database end. The form of packaging is the extra use of some keys, such as the "$query", "$orderby". We also have some of the following useful keys available:
1. $maxscan: integer Specify the maximum number of documents scanned when querying
2. $min: Start condition of document query
3. $max: End condition of document query
4. $hint: document Specifies which indexes the server uses to query
5. $explain: Boolean Gets
= "$not";
Geo operators public static final String WITHIN = "$within";
public static final String NEAR = "$near";
public static final String near_sphere = "$nearSphere";
public static final String box = "$box";
public static final String CENTER = "$center";
public static final String POLYGON = "$polygon"; public static Final String center_sphere = "$centerSphere";
(To is implemented in QueryBuilder) public static final String max_distance = "$maxDistance";
publ
achieve without sacrificing performance requirements.3. Cursors using cursors to return the results of find execution, the client's implementation of the cursor can often limit the number of results, skip partial results, sort, and more effectively control.var cursor = db. C.find ()--defining cursorswhile (Cursor.hasnext ()) {var obj = Cursor.next ();Print (OBJ.A);......}Db. C.find (). Limit (10)--Limit the number of results in a query to 10 barsDb. C.find (). Skip (10)--ignores the first 10 ma
: Db.test.find ({key01:{$in: [valu01,valu02,valu03]}}); SELECT * from TableName where key01 in (valu01,valu02,valu03)Operation of and: Db.collections.find ({key01:{$gte: $, $lte: 28}}); SELECT * from TableName where key01 >=24 and Key01 :d b.collections.find ({key01:valu02,key02:valu02}); SELECT * from TableName where key01=valu01 and key02=valu02Not equal to Operation: Db.collections.find ({key01:{$ne: valu01}}); SELECT * from TableName where key01 $not Related actions: Db.collections.find ({ke
this point, then any one element satisfies 1 of the criteria to be considered a match! But if it's not an array, match it at the same time! 20$elemmatch First, only the array elements will be matched Find ({"X": {"$elemMatch": {"$GT": Ten, "$lt": 20}}) 21 If an index is created Find ({"X": {"$GT": Ten, "$lt": $}}). min ({"X": Ten}). Max ({"X": 20}) The effect is very good! Because not all indexes are scanned, they are scanned in part of the index! 22 Querying inline documents Find ({"name": {"F
tune the results. Another way is to use the mapping of Jane-mapreduce.
V. Cursors
Cursors are useful things that the MongoDB database uses Grand to return find execution results. The client uses cursors to effectively control the end result, such as paging, sorting.
1, Limit,skip and sort
Limit: Limit the number of results, the limit is the limit.Skip: Skip the top n documents that match to, and then return the remaining documents. Skipping over too many documents results in performance p
use the index to filter by non-$where clauses, and finally use $where to tune the results. Another way is to use the mapping simplification-mapreduce. V. Cursors Cursors are useful things, and the MongoDB database uses cursors to return the execution results of find. The client uses cursors to effectively control the final results, such as paging and sorting. 1. Limit,skip and sort Limit: Limits the number of results, the limit is the upper limit.Skip: Skip to the first n documents that match,
Contact Us
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.